package jsurftwmm;

import java.util.List;
import java.util.Map;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.Serializable;

import jopensurf.InterestPoint;
import jopensurf.SURFInterestPoint;
import jopensurf.Surf;

public class SurfImage{

	private BufferedImage img;
	private Map<SURFInterestPoint, SURFInterestPoint> matchingPoint;
	private List<SURFInterestPoint> freeOrientedInterestPoints;
	private List<SURFInterestPoint> freeUpRightOrientedInterestPoints;
	private String name;
        private int simialirity;
        private String path;
        
	public SurfImage(BufferedImage read, String string, String path) {
		img = read;
		name = string;
                this.path = path;
        }

	public BufferedImage getImage() {

		return this.img;
	}
	
	public String getName(){
		return name;
	}
        public String getPath(){
            return this.path;
        }
        
        public Map<SURFInterestPoint, SURFInterestPoint> getMatchingPoint(){
		return matchingPoint;
	}
        
        public List<SURFInterestPoint> getfreeOrientedInterestPoints(){
		return freeOrientedInterestPoints;
	}

	public void setMatchingPoint(Map<SURFInterestPoint, SURFInterestPoint> map) {
            this.matchingPoint = map;

	}

	public int countMatchingPoint() {
		return this.matchingPoint.size();
	}

	public void setFreeOrientedInterestPoints(
			List<SURFInterestPoint> freeOrientedInterestPoints) {
		this.freeOrientedInterestPoints = freeOrientedInterestPoints;
	}

	public int countFreeOrientedInterestPoints(){
		return this.freeOrientedInterestPoints.size();
	}
      
        public int getSimilarity(){
           // return 100*this.matchingPoint.size()/this.freeOrientedInterestPoints.size();
            return this.simialirity;
        }
        
        public void setSimialirityTo(Surf image){
            int sum = 0;
            int k = 0;
            int size = 0;
            if (image.getFreeOrientedInterestPoints().size() > this.getfreeOrientedInterestPoints().size()){
                size =  this.getfreeOrientedInterestPoints().size();
            }else{
                size = image.getFreeOrientedInterestPoints().size();
            }
            for(int i=0; i < size; i++){
                for(int j=0; j < this.getfreeOrientedInterestPoints().size();j++){
                    int sizeA = image.getFreeOrientedInterestPoints().get(i).getLocation().length;
                    int sizeB = this.getfreeOrientedInterestPoints().get(i).getLocation().length;
                    double diff = image.getFreeOrientedInterestPoints().get(i).getLocation()[j%sizeA] - this.getfreeOrientedInterestPoints().get(i).getLocation()[j%sizeB];
                    sum += diff*diff;
                }
            }
            /*for(int i=0; i < image.getFreeOrientedInterestPoints().size(); i++){
                for(int j=0; j < image.getFreeOrientedInterestPoints().get(i).getLocation().length;j++){
                    double diff = image.getFreeOrientedInterestPoints().get(i).getLocation()[j] - this.getfreeOrientedInterestPoints().get(i).getLocation()[j];
                    sum += diff*diff;
                }
            }*/
            this.simialirity = (int) Math.sqrt(sum);
        }
        
    void setSimialirity(int i) {
       this.simialirity = i;
    }

    void setUprightInterestPoints(List<SURFInterestPoint> uprightInterestPoints) {
        this.freeUpRightOrientedInterestPoints = uprightInterestPoints;
    }
     public List<SURFInterestPoint> getUpRighFreeOrientedInterestPoints(){
        return this.freeUpRightOrientedInterestPoints;
     }
    
}
